
//
//  BarBerView.m
//  afn
//
//  Created by mac on 2018/5/8.
//  Copyright © 2018年 mac. All rights reserved.
//

#import "BarBerView.h"
#import "BarberCollectionView.h"
#import "BarberDetailsViewController.h"

@implementation BarBerView

-(void)creatView{
    self.backgroundColor=_LightGrey;
    
    UICollectionViewFlowLayout *flowLayout=[[UICollectionViewFlowLayout alloc] init];
    [flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical];
    
    self.collectionView=[[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, _mainW, _mainH-NAV_HEIGHT) collectionViewLayout:flowLayout];
    self.collectionView.dataSource=self;
    self.collectionView.delegate=self;
    [self.collectionView setBackgroundColor:[UIColor clearColor]];
    
    //注册Cell，必须要有
    [self.collectionView registerClass:[BarberCollectionView class] forCellWithReuseIdentifier:@"BarberCollectionView"];
    
    [self addSubview:self.collectionView];
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return _barerArr.count;
}
//定义展示的Section的个数
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    BarberCollectionView *cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"BarberCollectionView" forIndexPath:indexPath];
    cell.model=[BarberModel mj_objectWithKeyValues:_barerArr[indexPath.row]];
    [cell creatView];
    return cell;
    
}


//定义每个UICollectionView 的 margin
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    return UIEdgeInsetsMake(10, 10, 10, 10);
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake(_mainW/2-15, _mainW/2-15+40);
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    BarberModel *model=[BarberModel mj_objectWithKeyValues:_barerArr[indexPath.row]];
    BarberDetailsViewController *xiangQing=[[BarberDetailsViewController alloc] init];
    xiangQing.barber_id=model.barber_id;
    [gongju pushNextViewController:self.viewController andRootController:xiangQing];
}

@end
